package com.ctg.polling.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooEntity(finders = { "findPollsByExpireDateGreaterThan", "findPollsByExpireDateLessThan" })
public class Poll {

    @NotNull
    private java.lang.String question;

    @NotNull
    private java.lang.Boolean multipleChoice;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "S-")
    private Date expireDate;

    @NotNull
    @OneToMany(cascade = CascadeType.ALL)
    private Set<Choice> choices = new HashSet<Choice>();

    @NotNull
    @ManyToOne
    private JPollingUser author;

    /**
     * This transient property allows View component to know whether this
     * poll has already been answered by the current user. 
     */
    @Transient
    private boolean alreadyAnswered;

}